package com.cx.mq.rabbitmq.direct;

import com.cx.common.constant.MqConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author:chenxiaoyi
 * @Date:2020/8/8 16:20
 */
@Configuration
public class DirectConfig {

    /**
     * 定义直连交换机 -- 路由键传入交换机 并完全匹配到绑定交换机的队列
     */
    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange(MqConstant.Exchange.DIRECT);
    }
    @Bean
    public Queue queueA(){
        return new Queue(MqConstant.Queue.D_QUEUE_A);
    }
    @Bean
    public Queue queueB(){
        return new Queue(MqConstant.Queue.D_QUEUE_B);
    }

    /**
     * 绑定两个路由键
     */
    @Bean
    public Binding directBindingA(){
        return BindingBuilder.bind(queueA()).to(directExchange()).with(MqConstant.RoutingKey.D_ROUTINGKEY);
    }
    @Bean
    public Binding directBindingB(){
        return BindingBuilder.bind(queueB()).to(directExchange()).with(MqConstant.RoutingKey.D_ROUTINGKEY_O);
    }



}
